home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import wx
- from wx import WHITE_BRUSH, TRANSPARENT_PEN, FONTWEIGHT_BOLD
- from gui.textutil import default_font
- from gui.toolbox import build_button_sizer, snap_pref, persist_window_pos, AutoDC, calllimit
- from gui.validators import LengthLimit
- from gui.pref.prefstrings import all as allprefstrings, tabnames
- from util import import_function, Delegate, traceguard
- from common import profile
- from logging import getLogger
- log = getLogger('prefsdialog')
- prefstrings = dict((lambda .0: for name, module in .0:
- (name, ' '.join((lambda .0: for s in .0:
- s.lower().replace('&', ''))(module.itervalues())))
-
- )(allprefstrings.iteritems()))
- EXPAND_ALL = wx.EXPAND | wx.ALL
- wxMac = 'wxMac' in wx.PlatformInfo
-
- def show(tabname):
- if not isinstance(tabname, str):
- raise TypeError('prefsdialog.show takes a tab name')
-
- tabindex = [ c[0] for c in tabnames ].index(tabname)
- return show_prefs_window(None, tabindex)
-
-
- def show_prefs_window(parent, tab = 0):
- win = PrefsDialog.RaiseExisting()
- if win is not None:
- win.show_tab(tab)
- return win
-
- pdiag = PrefsDialog(None, initial_tab = tab)
- persist_window_pos(pdiag, position_only = True)
- wx.CallAfter(pdiag.Show)
- return pdiag
-
-
- class PrefsSearch(wx.SearchCtrl):
-
- def __init__(self, parent):
- wx.SearchCtrl.__init__(self, parent, -1, style = wx.TE_PROCESS_ENTER, validator = LengthLimit(128))
- self.ShowSearchButton(True)
-
-
-
- class PrefsTabs(wx.VListBox):
- item_height = 27
-
- def __init__(self, parent):
- wx.VListBox.__init__(self, parent, size = (130, -1))
- self.ItemCount = len(tabnames)
- self.spotlight_indices = set()
- self.Bind(wx.EVT_MOTION, self.OnMotion)
- self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
- self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
- self.UpdateSkin()
- self.tab_indices = dict((lambda .0: for modname, nicename in .0:
- (modname, i))(enumerate(tabnames)))
- self.hoveridx = -1
-
-
- def OnKey(self, e):
- e.Skip()
- if e.KeyCode == wx.WXK_ESCAPE:
- self.Top.Close()
-
-
-
- def OnLeave(self, e):
- self.Hover = -1
- e.Skip(True)
-
-
- def OnMotion(self, e):
- self.Hover = self.HitTest(e.Position)
- e.Skip(True)
-
-
- def get_hover(self):
- return self.hoveridx
-
-
- def set_hover(self, i):
- old = self.hoveridx
- self.hoveridx = i
- if i != old:
- if old != -1:
- self.RefreshLine(old)
-
- if i != -1:
- self.RefreshLine(i)
-
-
-
- Hover = property(get_hover, set_hover)
-
- def UpdateSkin(self):
- skin = skin
- import gui
- self.bgs = skin.get('AppDefaults.preftabs.backgrounds')
- self.BackgroundColour = wx.Colour(*self.bgs.normal)
-
-
- def tabname(self, index):
- return tabnames[index][1]
-
-
- def spotlight(self, tab_names):
- old = self.spotlight_indices
- self.spotlight_indices = (set,)((lambda .0: for name in .0:
- self.tab_indices[name])(tab_names))
- self.RefreshAll()
-
-
- def OnMeasureItem(self, n):
- return self.item_height
-
-
- def OnDrawItem(self, dc, rect, n):
- selected = self.GetSelection() == n
- font = default_font()
- if selected:
- font.SetWeight(FONTWEIGHT_BOLD)
-
- fh = font.Height
- dc.Font = font
- dc.TextForeground = wx.BLACK
- pt = wx.Point(*rect[:2]) + (5, self.item_height / 2 - fh / 2)
- dc.DrawText(self.tabname(n), *pt)
-
-
- def OnDrawBackground(self, dc, rect, n):
- selected = self.Selection == n
- hover = self.Hover == n
- dc.Pen = TRANSPARENT_PEN
- if n in self.spotlight_indices:
- self.bgs.search.Draw(dc, rect, n)
- elif selected:
- self.bgs.selected.Draw(dc, rect, n)
- elif hover:
- self.bgs.hover.Draw(dc, rect, n)
- else:
- self.bgs.normal.Draw(dc, rect, n)
-
-
- prefs_dialog_style = wx.DEFAULT_FRAME_STYLE & ~(wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)
-
- class PrefsDialog(wx.Frame):
- border = 5
- default_selected_tab = 1
- default_size = (700, 525)
-
- def __init__(self, parent, initial_tab = default_selected_tab):
- wx.Frame.__init__(self, parent, title = _('Digsby Preferences'), size = self.default_size, style = prefs_dialog_style, name = 'Preferences Window')
- self.loaded_panels = { }
- self.SetMinSize(self.default_size)
- self.create_gui()
- self.bind_events()
- self.layout_gui()
- self.exithooks = Delegate()
- traceguard.__enter__()
-
- try:
- skin = skin
- import gui
- self.SetFrameIcon(skin.get('AppDefaults.TaskbarIcon'))
- finally:
- pass
-
- if not wxMac:
- self.BackgroundColour = wx.WHITE
- self.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
-
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.tabs.SetSelection(initial_tab)
- self.on_tab_selected(initial_tab)
- self.Bind(wx.EVT_CLOSE, self.on_close)
- self._loaded = 0
- snap_pref(self)
- profile.prefs.add_observer(self.incoming_network_prefs)
- KeyCatcher = KeyCatcher
- import gui.uberwidgets.keycatcher
- k.OnDown('ctrl+w', self.Close)
- k.OnDown('escape', self.Close)
-
-
- def OnPaint(self, e):
- dc = AutoDC(self)
- crect = self.ClientRect
- if not wxMac:
- dc.Brush = WHITE_BRUSH
- dc.Pen = TRANSPARENT_PEN
- dc.DrawRectangleRect(crect)
-
- self.tabs.bgs.normal.Draw(dc, wx.Rect(0, 0, self.tabs.ClientRect.width, crect.height))
-
-
- def incoming_network_prefs(self, src, *a):
- wx.CallAfter(self._gui_incoming_network_prefs, src)
-
-
- def _gui_incoming_network_prefs(self, src):
- if src.isflagged('network'):
- wx.CallAfter(self.reload)
-
-
- _gui_incoming_network_prefs = calllimit(2)(_gui_incoming_network_prefs)
-
- def on_close(self, e):
- self.Hide()
- e.Skip()
- profile = profile
- import common
- profile.prefs.remove_observer(self.incoming_network_prefs)
- self.exithooks()
- for panel in self.loaded_panels.itervalues():
- if hasattr(panel, 'on_close'):
- traceguard.__enter__()
-
- try:
- panel.on_close()
- finally:
- pass
-
- continue
- traceguard
-
- profile.save('prefs')
- profile.save('notifications')
- memory_event = memory_event
- import gui.native
- memory_event()
-
-
- def create_gui(self):
- self.tabs = PrefsTabs(self)
- self.search = PrefsSearch(self)
- self.search.Bind(wx.EVT_TEXT, self.search_text)
- self.search.Bind(wx.EVT_TEXT_ENTER, self.search_enter)
- if not wxMac:
- self.save_button = wx.Button(self, wx.ID_SAVE, _('&Done'))
- self.save_button.SetDefault()
- self.save_button.Bind((wx.EVT_BUTTON,), (lambda e: self.Close()))
-
-
-
- def search_enter(self, e):
- if len(self.tabs.spotlight_indices) == 1:
- i = self.tabs.spotlight_indices.copy().pop()
- self.tabs.SetSelection(i)
- self.on_tab_selected(i)
-
-
-
- def search_text(self, e):
- wx.CallAfter(self._search)
-
-
- def _search(self):
- val = self.search.Value
- if val == 'Search':
- return None
-
- val = val.lower()
- if val == '':
- return self.tabs.spotlight([])
-
- tab_highlights = set()
- for module_name, stringset in prefstrings.iteritems():
- if val in stringset:
- tab_highlights.add(module_name)
- continue
-
- self.tabs.spotlight(tab_highlights)
-
-
- def bind_events(self):
- self.tabs.Bind(wx.EVT_LISTBOX, self.on_tab_selected)
-
-
- def layout_gui(self):
- self.content_sizer = wx.BoxSizer(wx.VERTICAL)
- hz = wx.BoxSizer(wx.HORIZONTAL)
- hz.Add(self.build_tab_sizer(), 0, EXPAND_ALL)
- hz.Add(self.content_sizer, 1, EXPAND_ALL)
- v = wx.BoxSizer(wx.VERTICAL)
- v.Add(hz, 1, EXPAND_ALL)
- if not wxMac:
- v.Add(build_button_sizer(self.save_button, border = self.border), 0, wx.EXPAND | wx.SOUTH | wx.EAST, 4)
-
- self.Sizer = v
-
-
- def build_tab_sizer(self):
- sz = wx.BoxSizer(wx.VERTICAL)
- sz.Add(self.search, 0, EXPAND_ALL, self.border)
- if wxMac:
- sz.AddSpacer(6)
-
- sz.Add(self.tabs, 1, EXPAND_ALL)
- return sz
-
-
- def on_tab_selected(self, e):
- index = None if isinstance(e, int) else e.Int
- if index != -1:
- self.tabs.Update()
- wx.CallAfter(self.show_panel, self.panel_for_tab(index))
-
-
-
- def show_tab(self, n):
- log.info('show_tab %d', n)
- self.tabs.SetSelection(n)
- self.show_panel(self.panel_for_tab(n))
-
-
- def reload(self):
- log.info('reloading Prefs dialog')
- self.Frozen().__enter__()
-
- try:
- child = self.content_sizer.Children[0]
- child.Show(False)
- self.content_sizer.Detach(0)
- for panel in self.loaded_panels.itervalues():
-
- try:
- panel.on_close()
- except AttributeError:
- self.Frozen()
- self.Frozen()
- except:
- self.Frozen()
-
- panel.Destroy()
-
- self.loaded_panels.clear()
- del self.exithooks[:]
- self.show_tab(self.tabs.GetSelection())
- finally:
- pass
-
-
-
- def show_panel(self, panel):
- if not isinstance(panel, wx.WindowClass):
- raise TypeError('show_panel takes a Window, you gave %r' % panel)
-
- self.FrozenQuick().__enter__()
-
- try:
- s = self.content_sizer
- if len(s.GetChildren()) > 0:
- s.Show(0, False)
- s.Detach(0)
-
- s.Add(panel, 1, EXPAND_ALL, 10)
- self.Layout()
- finally:
- pass
-
- wx.CallAfter(panel.Show)
-
-
- def panel_for_tab(self, i):
- module_name = tabnames[i][0]
- if module_name not in self.loaded_panels:
- log.info('loading panel "%s"', module_name)
- func = import_function('gui.pref.pg_%s.panel' % module_name)
- panel = self._construct_sub_panel(func)
- self.loaded_panels[module_name] = panel
-
- return self.loaded_panels[module_name]
-
-
- def _construct_sub_panel(self, func):
- PrefsPanel = PrefsPanel
- import gui.pref.prefcontrols
- p = PrefsPanel(self)
- p.Sizer = sz = wx.BoxSizer(wx.VERTICAL)
- szAdd = sz.Add
- PrefPanel = PrefPanel
- PrefCollection = PrefCollection
- import gui.uberwidgets.PrefPanel
-
- def addgroup(titleortuple, *workers, **options):
- if isinstance(titleortuple, tuple):
- (title, prefix) = titleortuple
- else:
- title = titleortuple
- prefix = ''
- group = PrefCollection(*workers, **options)
- panel = PrefPanel(p, group, title, prefix = prefix)
- szAdd(panel, 0, EXPAND_ALL, 3)
- return panel
-
- return func(p, sz, addgroup, self.exithooks)
-
-
-